package user

import (
	"github.com/gin-gonic/gin"
	"wskyygyso/api/pkg/app"
	"wskyygyso/api/pkg/database"
	"wskyygyso/api/pkg/paginator"
)

func IsEmailExists(email string) bool {
	var count int64
	database.DB.Model(User{}).Where("email = ?", email).Count(&count)
	return count > 0
}

func IsPhoneExists(phone string) bool {
	var count int64
	database.DB.Model(User{}).Where("phone = ?", phone).Count(&count)
	return count > 0
}

func IsEmailExist(email string) bool {
	var count int64
	database.DB.Model(User{}).Where("email = ?", email).Count(&count)
	return count > 0
}

func Paginate(c *gin.Context, perPage int) (users []User, paging paginator.Paging) {
	baseUrl := app.V1URL(database.TableName(&User{}))
	paging = paginator.Paginate(
		c,
		database.DB.Model(User{}),
		&users,
		baseUrl,
		perPage,
	)
	return
}
